home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Amiga Tools 2
/
Amiga Tools 2.iso
/
tex
/
macros
/
source
/
contrib
/
fp
/
fp-random.sty
< prev
next >
Wrap
Text File
|
1995-03-09
|
2KB
|
93 lines
\NeedsTeXFormat{LaTeX2e}
\ProvidesPackage{fp-random}[1995/02/17]
% Version information
\def\FP@randomversion{1.0}
\message{%
`Fixed Point Random,%
\space\space\space\space\space\space\space\space\space\space\space\space%
Version \FP@randomversion%
\space(C) Denis Girou (CNRS/IDRIS)%
}
% Resolve dependencies
\RequirePackage{fp-basic}
% Uniform random value
\newcount\FPseed % Seed value
\def\FPrandom#1{%
% #1 macro, which gets the result
%
% Uniform random number generator (numbers between 0 and 1)
%
% Algorithm reproduce from a very old Fortran program (unknown origin!)
%
% double precision function RANF()
%
% integer SEED
% common /COMSEED/SEED
% *
% integer A,M,Q,R
% parameter(A=16807,M=2147483647,Q=127773,R=2836)
% *
% integer LO,HI,TEST
% *
% HI = SEED/Q
% LO = SEED-HI*Q
% TEST = A*LO-R*HI
% if(TEST.gt.0) then
% SEED = TEST
% else
% SEED = TEST+M
% endif
% *
% RANF = DFLOAT(SEED)/DFLOAT(M)
% *
% end
%
% The macro used a seed value, defined by the counter \FPseed.
% If it's unknown at first call, we used an arbitrary value.
%
% We verify that we obtain the same results as in Fortran
%
{\FP@beginmessage{RANDOM}%
%
\ifnum\FPseed=0%
\FPseed=123456789%
\FP@debug{random: seed value undefined! We will used \the\FPseed.^^J%
Define it if you want to generate a different sequence of random%
numbers.}%
\else%
\FP@debug{random: seed value used: \the\FPseed}%
\fi%
%
\FP@xia=\FPseed%
\divide\FP@xia by 127773%
\FP@xib=\FP@xia%
\multiply\FP@xib by 127773%
\advance\FP@xib by -\FPseed%
\FP@xib=-\FP@xib%
\multiply\FP@xia by 2836%
\FPseed=\FP@xib%
\multiply\FPseed by 16807%
\advance\FPseed by -\FP@xia%
%
\ifnum\FPseed>0%
\else%
\advance\FPseed by 2147483647%
\fi%
\FPdiv\FP@tmpa{\the\FPseed}{2147483647}%
\global\let\FP@tmp\FP@tmpa%
\global\FPseed=\FPseed%
\FP@debug{random: random number: \FP@tmp\space%
(new seed value: \the\FPseed)}%
%
\FP@endmessage{}%
}%
\let#1\FP@tmp%
}
\endinput